package StringBuilder.exercise;

import java.util.ArrayList;
import java.util.Scanner;

////键盘录入学生的信息， 把学生信息(每个学生都有姓名和年龄)封装为 学生对象， 总共录入5个学生对象，  然后把学生对象 存入到集合中
////然后遍历集合 打印每一个学生的信息。
public class Work3 {
    public static void main(String[] args) {
        ArrayList<Students> Array=new ArrayList<>();
        Students st1=Student();
        Students st2=Student();
        Students st3=Student();
        Students st4=Student();
        Students st5=Student();
        Array.add(st1);
        Array.add(st2);
        Array.add(st3);
        Array.add(st4);
        Array.add(st5);
        for (int i = 0; i < Array.size(); i++) {
            Students str=Array.get(i);
            System.out.println(str.getName()+"..."+str.getAge());
        }
    }

    private static Students Student() {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生姓名：");
        String name=sc.next();
        System.out.println("请输入学生年龄：");
        int age = sc.nextInt();
        return new Students(name,age);
    }
}
class Students{
    private String name;
    private int age;

    public Students() {
    }

    public Students(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
